/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2023-2023. All rights reserved.
 * Description: TbeVectorReduce类的实现文件
 * Author: jiasonghua
 * Create: 2023-2-3
 */

#ifndef TBE_CRACK_CLEARED_H
#define TBE_CRACK_CLEARED_H

#include <string>
#include <unordered_map>
#include <nlohmann/json.hpp>
#include <hccl/hccl_types.h>
#include <mutex>
#include <map>
#include <list>
#include <hccl/base.h>
#include "tbe_vector_reduce.h"
#ifndef HCCD
#include "runtime/rt.h"
#endif
#include "op_tiling.h"

namespace TbeReduce {
constexpr u32 MEMSET_CRACK_TILING_DATA_MAX_SZIE = 64;
constexpr u32 MEMSET_ALIGNMENT_CRACK_LIST_MAX_SZIE = 32;

class TbeCrackCleard : public TbeVectorReduce {
public:
    explicit TbeCrackCleard();
    ~TbeCrackCleard() override;
    HcclResult Init();
    HcclResult Run(std::vector<std::int64_t> &crackAddr, std::vector<std::int64_t> &crackSize,\
        HcclRtStream stream);
private:
    void InitOpInfoMap910A();
    void InitOpInfoMap310P3();
    void InitOpInfoMap910B();
    HcclResult GetOpInfo(nlohmann::json &opDescInfo, nlohmann::json &opTilingInfo);
    HcclResult GetTilingRunInfo(nlohmann::json &opDescInfo, nlohmann::json &opTilingInfo, OpRunInfo &runInfo,\
        std::vector<std::int64_t> &crackSize);
    HcclResult ExecuteKernelLaunch(std::vector<std::int64_t> &crackAddr, void *stream, const void *stubFunc,\
        OpRunInfo &runInfo, void *tilingDataDevPtr);
    HcclResult GetopInfoIndex(std::string &opInfoIndex);

    std::map<std::string, nlohmann::json> opInfoMap_;
    std::mutex crackDataMutex_;
    void *addrListDevPtr_;
    bool initTilingDataHostPtr_;
};
} // namespace TbeReduce
#endif